﻿using BarcodePrinting;
using OrderSystem.Common;
using OrderSystem.DataAccess;
using OrderSystem.FormatOutput;
using OrderSystem.NPOIOperateExcel;
using OrderSystem.SystemFramework;
using OrderSystem.Templet;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;

namespace OrderSystem
{
    public partial class FormOrderInfo : FormTemplet
    {
        private string _hostIPAddress = null;

        private DataTable _dtOrderItems = null;

        private FormAddOrderItem frmAddOrderItem;

        private FormUpdateOrderItem frmUpdateOrderItem;

        private long _nOrderID = -1L;

        private string _sOrderCode = null;

        private int _nCustomerID = -1;

        private string _sCompanyName = null;

        private string _sCompanyLinkman = null;

        private int _nProjectID = -1;

        private string _sProjectName = null;

        private string _sProjectLinkman = null;

        private string _sProjectLinkmanPhone = null;

        private string _sProjectAddress = null;

        private string _sOrderDate = null;

        private string _sSpeakForDate = null;

        private string _sDeliveryDate = null;

        private bool _isLailiao = false;

        private bool _isQuliao = false;

        private bool _isPayed = false;

        private string _sPayedDate = null;

        private decimal _mActualPayment = 0m;

        private bool _isEdited = false;

        private bool _isLocked = true;

        private bool _isCancelled = false;

        private bool _isLockedFlowcard = true;

        private string _sRemark = null;

        private string _sYaoqiu = null;

        private string _sProcessflow = null;

        private string _sCustomerNameOnPrintedLabel = null;

        private int _nOperatorID = -1;

        private string _sOperatorName = null;

        private string _sSalesPerson = null;

        private string _sOriginalValue = "";

        public FormOrderInfo()
        {
            this.InitializeComponent();
        }

        public FormOrderInfo(string sOrderCode) : this()
        {
            this._sOrderCode = sOrderCode;
            this.RefreshOrder();
            this.RefreshItems();
        }

        private void RefreshOrder()
        {
            DataTable dataTable = null;
            Orders orders = new Orders();
            try
            {
                dataTable = orders.LoadOrderByOrderCode(this._sOrderCode);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            orders.Dispose();
            if (dataTable != null)
            {
                if (dataTable.Rows.Count > 0)
                {
                    this._nOrderID = (long)Convert.ToInt32(dataTable.Rows[0]["订单序号"]);
                    this._nCustomerID = Convert.ToInt32(dataTable.Rows[0]["客户序号"]);
                    this._sCompanyName = dataTable.Rows[0]["公司名称"].ToString();
                    this._sCompanyLinkman = dataTable.Rows[0]["公司联系人"].ToString();
                    this._nProjectID = Convert.ToInt32(dataTable.Rows[0]["计划序号"]);
                    this._sProjectName = dataTable.Rows[0]["计划名称"].ToString();
                    this._sProjectLinkman = dataTable.Rows[0]["计划联系人"].ToString();
                    this._sProjectLinkmanPhone = dataTable.Rows[0]["计划联系人电话"].ToString();
                    this._sProjectAddress = dataTable.Rows[0]["计划地址"].ToString();
                    this._sOrderDate = dataTable.Rows[0]["下单日期"].ToString();
                    this._sSpeakForDate = dataTable.Rows[0]["订单日期"].ToString();
                    this._sDeliveryDate = DateTime.Parse(dataTable.Rows[0]["交货日期"].ToString()).ToShortDateString();
                    this._isLailiao = Convert.ToBoolean(dataTable.Rows[0]["是否来料"]);
                    this._isQuliao = Convert.ToBoolean(dataTable.Rows[0]["是否去料"]);
                    this._isPayed = Convert.ToBoolean(dataTable.Rows[0]["是否结算"]);
                    this._sPayedDate = dataTable.Rows[0]["结算序号"].ToString();
                    this._mActualPayment = Convert.ToDecimal(dataTable.Rows[0]["实际付款"]);
                    this._isEdited = Convert.ToBoolean(dataTable.Rows[0]["编辑完成"]);
                    this._isLocked = Convert.ToBoolean(dataTable.Rows[0]["是否锁定"]);
                    this._isCancelled = Convert.ToBoolean(dataTable.Rows[0]["是否作废"]);
                    this._isLockedFlowcard = Convert.ToBoolean(dataTable.Rows[0]["锁定流程卡"]);
                    this._sRemark = dataTable.Rows[0]["订单备注"].ToString();
                    this._sYaoqiu = dataTable.Rows[0]["加工要求"].ToString();
                    this._sProcessflow = dataTable.Rows[0]["工艺流程"].ToString();
                    this._sCustomerNameOnPrintedLabel = dataTable.Rows[0]["标签上的客户名称"].ToString();
                    this._nOperatorID = Convert.ToInt32(dataTable.Rows[0]["操作者ID"]);
                    this._sOperatorName = dataTable.Rows[0]["操作者"].ToString();
                    this._sSalesPerson = dataTable.Rows[0]["业务员"].ToString();
                    this.txtOrderCode.Text = this._sOrderCode;
                    this.txtCompanyName.Text = string.Concat(new string[]
                    {
                        this._sCompanyName,
                        "(",
                        this._sProjectName,
                        "<",
                        this._sProjectLinkman,
                        ">)"
                    });
                    this.txtProjectAddress.Text = this._sProjectAddress + "(" + this._sProjectLinkmanPhone + ")";
                    this.txtOrderDate.Text = this._sOrderDate;
                    this.txtSpeakForDate.Text = this._sSpeakForDate + "  交货日期:" + this._sDeliveryDate;
                    this.ckLailiao.Checked = this._isLailiao;
                    this.ckQuliao.Checked = this._isQuliao;
                    this.chkPayment.Checked = this._isPayed;
                    this.txtPayedDate.Text = this._sPayedDate;
                    this.chkEdited.Checked = this._isEdited;
                    this.chkLockedData.Checked = this._isLocked;
                    this.chkCancelled.Checked = this._isCancelled;
                    this.menuLockFlowcard.Checked = this._isLockedFlowcard;
                    this.txtRemark.Text = this._sRemark;
                    this.txtYaoqiu.Text = this._sYaoqiu;
                    this.txtProcessFlow.Text = this._sProcessflow;
                    this.txtLabelName.Text = this._sCustomerNameOnPrintedLabel;
                    this.txtOperatorName.Text = this._sOperatorName;
                    this.txtSalesPerson.Text = this._sSalesPerson;
                }
                else
                {
                    MessageBox.Show("没有查询到此订单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                dataTable.Dispose();
            }
            this.RefreshAttachments();
        }

        public void RefreshItems()
        {
            DataTable dataTable = null;
            OrderItems orderItems = new OrderItems();
            try
            {
                Sequence eSequence;
                if (this.menuDataSequenceByInput.Checked)
                {
                    eSequence = Sequence.ByPKID;
                }
                else
                {
                    eSequence = Sequence.BySize;
                }
                dataTable = orderItems.GetOrderItems(this._nOrderID, eSequence);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！\r\n\r\n订单项信息可能没有读出来", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message + "\r\n\r\n订单项信息可能没有读出来", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            orderItems.Dispose();
            if (dataTable != null)
            {
                if (this._dtOrderItems != null)
                {
                    this._dtOrderItems.Dispose();
                    this._dtOrderItems = null;
                }
                this._dtOrderItems = dataTable;
                this.dgProducts.DataSource = this._dtOrderItems;
                this.dgProducts.AutoResizeColumns();
                bool flag = false;
                for (int i = 0; i < this._dtOrderItems.Rows.Count; i++)
                {
                    if (this._dtOrderItems.Rows[i]["宽(短边)"].ToString().Length > 0 || this._dtOrderItems.Rows[i]["高(短边)"].ToString().Length > 0)
                    {
                        flag = true;
                        this.dgProducts.Columns["宽(短边)"].Visible = true;
                        this.dgProducts.Columns["高(短边)"].Visible = true;
                        break;
                    }
                }
                if (!flag)
                {
                    this.dgProducts.Columns["宽(短边)"].Visible = false;
                    this.dgProducts.Columns["高(短边)"].Visible = false;
                }
            }
            else
            {
                MessageBox.Show("加载此订单的数据失败！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        public void RefreshAttachments()
        {
            DataTable dataTable = null;
            Orders orders = new Orders();
            try
            {
                dataTable = orders.GetAttachments(this._sOrderCode);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            orders.Dispose();
            if (dataTable != null)
            {
                if (dataTable.Rows.Count > 0)
                {
                    this.txtAttachmentName.Text = "";
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        TextBox expr_A7 = this.txtAttachmentName;
                        expr_A7.Text = expr_A7.Text + dataTable.Rows[i][1].ToString() + ((dataTable.Rows[i][2].ToString() != "") ? ("(" + dataTable.Rows[i][2].ToString() + ")") : "") + ";";
                    }
                }
                else
                {
                    this.txtAttachmentName.Text = "";
                }
            }
        }

        public void ReloadOrderItemsForInsert(string sProductID, string sProductType, string sUnit, string sProductCode, decimal mWidth, string sSubtenseOfWidth, decimal mHeight, string sSubtenseOfHeight, string sSpecialShapedName, int nQuantity, decimal mPrice, string sRemark, string sTechnics)
        {
            if (this.menuShowData.Checked)
            {
                if (this._dtOrderItems == null)
                {
                    MessageBox.Show("数据容器是空，可能还有数据保存在数据库，但没有加载到容器中，你可以从新打开此订单试一试，但是现有数据将加载在此容器中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this._dtOrderItems = new DataTable("OrderItem");
                    this._dtOrderItems.Columns.Add(new DataColumn("产品ID", typeof(string)));
                    this._dtOrderItems.Columns.Add(new DataColumn("类型", typeof(string)));
                    this._dtOrderItems.Columns.Add(new DataColumn("单位", typeof(string)));
                    this._dtOrderItems.Columns.Add(new DataColumn("编号", typeof(string)));
                    this._dtOrderItems.Columns.Add(new DataColumn("宽", typeof(decimal)));
                    this._dtOrderItems.Columns.Add(new DataColumn("宽(短边)", typeof(string)));
                    this._dtOrderItems.Columns.Add(new DataColumn("高", typeof(decimal)));
                    this._dtOrderItems.Columns.Add(new DataColumn("高(短边)", typeof(string)));
                    //this._dtOrderItems.Columns.Add(new DataColumn("加工要求", typeof(string)));
                    this._dtOrderItems.Columns.Add(new DataColumn("加工要求", typeof(string)));
                    this._dtOrderItems.Columns.Add(new DataColumn("数量", typeof(int)));
                    this._dtOrderItems.Columns.Add(new DataColumn("面积", typeof(decimal)));
                    this._dtOrderItems.Columns.Add(new DataColumn("价格", typeof(decimal)));
                    this._dtOrderItems.Columns.Add(new DataColumn("备注", typeof(string)));
                    this._dtOrderItems.Columns.Add(new DataColumn("工艺", typeof(string)));
                    this.dgProducts.DataSource = this._dtOrderItems;
                }
                DataRow dataRow = this._dtOrderItems.NewRow();
                dataRow[0] = sProductID;
                dataRow[1] = sProductType;
                dataRow[2] = sUnit;
                dataRow[3] = sProductCode;
                dataRow[4] = mWidth;
                dataRow[5] = sSubtenseOfWidth;
                dataRow[6] = mHeight;
                dataRow[7] = sSubtenseOfHeight;
                dataRow[8] = sSpecialShapedName;
                dataRow[9] = nQuantity;
                dataRow[10] = Convert.ToDouble(Convert.ToDecimal((mWidth * mHeight / 1000000m).ToString("F4")) * nQuantity);
                dataRow[11] = Convert.ToDouble(mPrice);
                dataRow[12] = sRemark;
                dataRow[13] = sTechnics;
                this._dtOrderItems.Rows.Add(dataRow);
                this._dtOrderItems.AcceptChanges();
                for (int i = 0; i < this._dtOrderItems.Rows.Count; i++)
                {
                    if (this.dgProducts.Rows[i].Cells[0].Value.ToString() == sProductID)
                    {
                        this.dgProducts.CurrentCell = this.dgProducts.Rows[i].Cells[0];
                        this.dgProducts.Rows[i].Selected = true;
                        break;
                    }
                }
                this.dgProducts.AutoResizeColumns();
            }
        }

        public void ReloadOrderItemsForUpdate(string sProductID, string sProductType, string sUnit, string sProductCode, decimal mWidth, string sSubtenseOfWidth, decimal mHeight, string sSubtenseOfHeight, string sSpecialShapedName, int nQuantity, decimal mPrice, string sRemark, string sTechnics)
        {
            if (this._dtOrderItems == null)
            {
                MessageBox.Show("数据容器是空，不能装载数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                for (int i = 0; i < this._dtOrderItems.Rows.Count; i++)
                {
                    if (sProductID == this._dtOrderItems.Rows[i][0].ToString())
                    {
                        DataRow dataRow = this._dtOrderItems.Rows[i];
                        dataRow[0] = sProductID;
                        dataRow[1] = sProductType;
                        dataRow[2] = sUnit;
                        dataRow[3] = sProductCode;
                        dataRow[4] = mWidth;
                        dataRow[5] = sSubtenseOfWidth;
                        dataRow[6] = mHeight;
                        dataRow[7] = sSubtenseOfHeight;
                        dataRow[8] = sSpecialShapedName;
                        dataRow[9] = nQuantity;
                        dataRow[10] = Convert.ToDouble(Convert.ToDecimal((mWidth * mHeight / 1000000m).ToString("F4")) * nQuantity);
                        dataRow[11] = Convert.ToDouble(mPrice);
                        dataRow[12] = sRemark;
                        dataRow[13] = sTechnics;
                        break;
                    }
                }
                this._dtOrderItems.AcceptChanges();
                for (int i = 0; i < this._dtOrderItems.Rows.Count; i++)
                {
                    if (this.dgProducts.Rows[i].Cells[0].Value.ToString() == sProductID)
                    {
                        this.dgProducts.CurrentCell = this.dgProducts.Rows[i].Cells[0];
                        this.dgProducts.Rows[i].Selected = true;
                        break;
                    }
                }
                this.dgProducts.AutoResizeColumns();
            }
        }

        public void ReloadOrderItemsForUpdate(string sProductID, string sTechnics)
        {
            if (this._dtOrderItems == null)
            {
                MessageBox.Show("数据容器是空，不能装载数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                for (int i = 0; i < this._dtOrderItems.Rows.Count; i++)
                {
                    if (sProductID == this._dtOrderItems.Rows[i][0].ToString())
                    {
                        DataRow dataRow = this._dtOrderItems.Rows[i];
                        dataRow[0] = sProductID;
                        dataRow[13] = sTechnics;
                        break;
                    }
                }
                this._dtOrderItems.AcceptChanges();
                this.dgProducts.AutoResizeColumns();
            }
        }

        private void FormOrderInfo_Load(object sender, EventArgs e)
        {
            this.dgProducts.AutoResizeColumns();
            IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
            this._hostIPAddress = hostEntry.AddressList[0].ToString() + "(" + hostEntry.HostName + ")";
            if (!LoginInfo.Role[PowerName.OrderData_SeePrice])
            {
                if (this.dgProducts != null)
                {
                    this.dgProducts.Columns["价格"].Visible = false;
                }
            }
        }

        private void btnAddOrderItem_Click(object sender, EventArgs e)
        {
            this.menuAddOrderItem_Click(null, null);
        }

        private void menuAddOrderItem_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Create])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                if (this.frmAddOrderItem == null || this.frmAddOrderItem.IsDisposed)
                {
                    this.frmAddOrderItem = new FormAddOrderItem(this._nOrderID, this);
                    this.frmAddOrderItem.MdiParent = base.MdiParent;
                }
                this.frmAddOrderItem.TopMost = true;
                this.frmAddOrderItem.Show();
                this.frmAddOrderItem.Activate();
            }
        }

        private void btnUpdateOrderItem_Click(object sender, EventArgs e)
        {
            this.menuUpdateOrderItem_Click(null, null);
        }

        private void menuUpdateOrderItem_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                try
                {
                    string text = this.dgProducts.Rows[0].Cells[0].Value.ToString();
                }
                catch
                {
                    MessageBox.Show("表格中没有数据", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                int rowIndex = this.dgProducts.CurrentCell.RowIndex;
                if (this.frmUpdateOrderItem == null || this.frmUpdateOrderItem.IsDisposed)
                {
                    this.frmUpdateOrderItem = new FormUpdateOrderItem(this.dgProducts.Rows[rowIndex].Cells[0].Value.ToString(), this);
                    this.frmUpdateOrderItem.MdiParent = base.MdiParent;
                }
                this.frmUpdateOrderItem.Show();
                this.frmUpdateOrderItem.Activate();
            }
        }

        private void btnDeleteOrderItem_Click(object sender, EventArgs e)
        {
            this.menuDeleteOrderItem_Click(null, null);
        }

        private void dgProducts_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                this.menuDeleteOrderItem_Click(null, null);
            }
        }

        private void menuDeleteOrderItem_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                try
                {
                    string text = this.dgProducts.Rows[0].Cells[0].Value.ToString();
                }
                catch
                {
                    MessageBox.Show("表格中没有数据", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                if (MessageBox.Show("是否真的要删除这些选中的数据吗 ？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Cancel)
                {
                    OrderItems orderItems = new OrderItems();
                    try
                    {
                        ArrayList arrayList = new ArrayList();
                        for (int i = 0; i < this.dgProducts.SelectedRows.Count; i++)
                        {
                            arrayList.Add(this.dgProducts.SelectedRows[i].Cells[0].Value.ToString());
                        }
                        for (int i = 0; i < arrayList.Count; i++)
                        {
                            orderItems.DeleteOrderItem(arrayList[i].ToString(), LoginInfo.OperatorID);
                            for (int j = 0; j < this._dtOrderItems.Rows.Count; j++)
                            {
                                if (this._dtOrderItems.Rows[j][0].ToString() == arrayList[i].ToString())
                                {
                                    DataRow dataRow = this._dtOrderItems.Rows[j];
                                    dataRow.Delete();
                                    dataRow.AcceptChanges();
                                    break;
                                }
                            }
                        }
                    }
                    catch (SqlException ex)
                    {
                        int number = ex.Number;
                        if (number != 50001)
                        {
                            switch (number)
                            {
                                case 50100:
                                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    this.chkLockedData.Checked = true;
                                    break;
                                case 50101:
                                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    this.chkCancelled.Checked = true;
                                    break;
                                case 50102:
                                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    this.menuEditData.Checked = false;
                                    break;
                                case 50103:
                                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    break;
                                default:
                                    if (number != 50200)
                                    {
                                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                    else
                                    {
                                        MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                    break;
                            }
                        }
                        else
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orderItems.Dispose();
                }
            }
        }

        private void menuImportData_Click(object sender, EventArgs e)
        {
            int nProductTypeID = -1;
            ProductTypeData productTypeData = FormSelectProductType.ShowBox();
            if (productTypeData != null)
            {
                nProductTypeID = productTypeData.ProductTypeID;
                DataTable dataTable = null;
                this.openFileDialog1.Filter = "Excel(*.xls)|*.xls";
                this.openFileDialog1.Title = "请选择你要导入的文件";
                this.openFileDialog1.FileName = "";
                if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string fileName = this.openFileDialog1.FileName;
                    ExcelToOrder excelToOrder = new ExcelToOrder();
                    try
                    {
                        dataTable = excelToOrder.GetOrderDataFromExcel(fileName);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    if (dataTable == null || dataTable.Rows.Count == 0)
                    {
                        MessageBox.Show("没有数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        OrderItems orderItems = new OrderItems();
                        try
                        {
                            for (int i = 0; i < dataTable.Rows.Count; i++)
                            {
                                string text = orderItems.InsertOrderItem(this._nOrderID, nProductTypeID, dataTable.Rows[i][1].ToString(), Convert.ToDecimal(dataTable.Rows[i][2]), "", Convert.ToDecimal(dataTable.Rows[i][3]), "", "", Convert.ToInt32(dataTable.Rows[i][4]), Convert.ToDecimal(dataTable.Rows[i][6]), dataTable.Rows[i][7].ToString(), LoginInfo.OperatorID, "");
                            }
                        }
                        catch (SqlException ex2)
                        {
                            int number = ex2.Number;
                            if (number != 50001)
                            {
                                switch (number)
                                {
                                    case 50100:
                                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        this.chkLockedData.Checked = true;
                                        break;
                                    case 50101:
                                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        this.chkCancelled.Checked = true;
                                        break;
                                    case 50102:
                                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        this.menuEditData.Checked = false;
                                        break;
                                    case 50103:
                                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        break;
                                    default:
                                        MessageBox.Show(ex2.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        break;
                                }
                            }
                            else
                            {
                                MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        orderItems.Dispose();
                        this.RefreshItems();
                    }
                }
            }
        }

        private void menuUpdateProductType_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                ProductTypeData productTypeData = FormSelectProductType.ShowBox();
                if (productTypeData != null)
                {
                    int productTypeID = productTypeData.ProductTypeID;
                    string text = InputBox.ShowBox("请输入你所要修改产品类型的价格...", "");
                    if (text != null)
                    {
                        text = CommonMethod.Fun1(text.Trim());
                        if (!Regex.IsMatch(text, "^(([0-9]{1,})|([0-9]{1,}\\.[0-9]{1,4}))$") || Convert.ToDecimal(text) < 0m)
                        {
                            MessageBox.Show("价格 格式不正确，此处应该为不为负的数字，如有小数，最大为4位小数", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        else
                        {
                            OrderItems orderItems = new OrderItems();
                            bool flag = false;
                            try
                            {
                                flag = orderItems.UpdateProductType(this._sOrderCode, productTypeID, Convert.ToDecimal(text));
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            orderItems.Dispose();
                            if (flag)
                            {
                                this.RefreshItems();
                                MessageBox.Show("产品类型 更改成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            }
                        }
                    }
                }
            }
        }

        private void menuUpdateProductTypeForSelect_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.dgProducts.SelectedRows.Count == 0)
            {
                MessageBox.Show("没有选择数据行，请选择数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string[] array = new string[this.dgProducts.SelectedRows.Count];
                for (int i = 0; i < this.dgProducts.SelectedRows.Count; i++)
                {
                    array[i] = this.dgProducts.SelectedRows[i].Cells["产品ID"].Value.ToString();
                }
                ProductTypeData productTypeData = FormSelectProductType.ShowBox();
                if (productTypeData != null)
                {
                    int productTypeID = productTypeData.ProductTypeID;
                    string text = InputBox.ShowBox("请输入你所要修改产品类型的价格...", "");
                    if (text != null)
                    {
                        text = CommonMethod.Fun1(text.Trim());
                        if (!Regex.IsMatch(text, "^(([0-9]{1,})|([0-9]{1,}\\.[0-9]{1,4}))$") || Convert.ToDecimal(text) < 0m)
                        {
                            MessageBox.Show("价格 格式不正确，此处应该为不为负的数字，如有小数，最大为4位小数", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        else
                        {
                            OrderItems orderItems = new OrderItems();
                            bool flag = false;
                            try
                            {
                                flag = orderItems.UpdateProductType(array, productTypeID, Convert.ToDecimal(text));
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            orderItems.Dispose();
                            if (flag)
                            {
                                this.RefreshItems();
                                MessageBox.Show("产品类型 更改成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            }
                        }
                    }
                }
            }
        }

        private void menuUpdateProductCodeForSelect_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.dgProducts.SelectedRows.Count == 0)
            {
                MessageBox.Show("没有选择数据行，请选择数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string[] array = new string[this.dgProducts.SelectedRows.Count];
                for (int i = 0; i < this.dgProducts.SelectedRows.Count; i++)
                {
                    array[i] = this.dgProducts.SelectedRows[i].Cells["产品ID"].Value.ToString();
                }
                string text = InputBox.ShowBox("请输入你所要修改产品编号...", "");
                if (text != null)
                {
                    text = text.Trim();
                    if (text.Length > 32)
                    {
                        MessageBox.Show("编号 格式不正确，此处应该在 32 个字符之内", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        OrderItems orderItems = new OrderItems();
                        bool flag = false;
                        try
                        {
                            flag = orderItems.UpdateProductCode(array, text);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        orderItems.Dispose();
                        if (flag)
                        {
                            this.RefreshItems();
                            MessageBox.Show("更改成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
            }
        }

        private void menuUpdateProductQuantity1_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = InputBox.ShowBox("请输入你所要修改产品数量所要加的数量...", "");
                if (text != null)
                {
                    text = text.Trim();
                    if (!Regex.IsMatch(text, "^[0-9]{1,8}$") || Convert.ToDecimal(text) <= 0m)
                    {
                        MessageBox.Show("数量 格式不正确，此处应该为大于零的整数", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else if (this.dgProducts.SelectedRows.Count == 0)
                    {
                        MessageBox.Show("没有选择数据行，请选择数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        string[] array = new string[this.dgProducts.SelectedRows.Count];
                        for (int i = 0; i < this.dgProducts.SelectedRows.Count; i++)
                        {
                            array[i] = this.dgProducts.SelectedRows[i].Cells["产品ID"].Value.ToString();
                        }
                        OrderItems orderItems = new OrderItems();
                        bool flag = false;
                        try
                        {
                            flag = orderItems.UpdateProductQuantity(array, Convert.ToInt32(text), '+');
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        orderItems.Dispose();
                        if (flag)
                        {
                            this.RefreshItems();
                            MessageBox.Show("更改成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
            }
        }

        private void menuUpdateProductQuantity2_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = InputBox.ShowBox("请输入你所要修改产品数量所要减的数量...", "");
                if (text != null)
                {
                    text = text.Trim();
                    if (!Regex.IsMatch(text, "^[0-9]{1,8}$") || Convert.ToDecimal(text) <= 0m)
                    {
                        MessageBox.Show("数量 格式不正确，此处应该为大于零的整数", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else if (this.dgProducts.SelectedRows.Count == 0)
                    {
                        MessageBox.Show("没有选择数据行，请选择数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        string[] array = new string[this.dgProducts.SelectedRows.Count];
                        for (int i = 0; i < this.dgProducts.SelectedRows.Count; i++)
                        {
                            array[i] = this.dgProducts.SelectedRows[i].Cells["产品ID"].Value.ToString();
                            if (Convert.ToInt32(this.dgProducts.SelectedRows[i].Cells["数量"].Value) <= Convert.ToInt32(text))
                            {
                                MessageBox.Show(array[i] + "的数量不能小于或等于所减的数量！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                        }
                        OrderItems orderItems = new OrderItems();
                        bool flag = false;
                        try
                        {
                            flag = orderItems.UpdateProductQuantity(array, Convert.ToInt32(text), '-');
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        orderItems.Dispose();
                        if (flag)
                        {
                            this.RefreshItems();
                            MessageBox.Show("更改成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
            }
        }

        private void menuUpdateProductQuantity3_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = InputBox.ShowBox("请输入你所要修改产品数量所要乘的数量...", "");
                if (text != null)
                {
                    text = text.Trim();
                    if (!Regex.IsMatch(text, "^[0-9]{1,8}$") || Convert.ToDecimal(text) <= 0m)
                    {
                        MessageBox.Show("数量 格式不正确，此处应该为大于零的整数", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else if (this.dgProducts.SelectedRows.Count == 0)
                    {
                        MessageBox.Show("没有选择数据行，请选择数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        string[] array = new string[this.dgProducts.SelectedRows.Count];
                        for (int i = 0; i < this.dgProducts.SelectedRows.Count; i++)
                        {
                            array[i] = this.dgProducts.SelectedRows[i].Cells["产品ID"].Value.ToString();
                        }
                        OrderItems orderItems = new OrderItems();
                        bool flag = false;
                        try
                        {
                            flag = orderItems.UpdateProductQuantity(array, Convert.ToInt32(text), '*');
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        orderItems.Dispose();
                        if (flag)
                        {
                            this.RefreshItems();
                            MessageBox.Show("更改成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
            }
        }

        private void menuUpdateProductQuantity4_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = InputBox.ShowBox("请输入你所要修改产品数量所要除的数量...", "");
                if (text != null)
                {
                    text = text.Trim();
                    if (!Regex.IsMatch(text, "^[0-9]{1,8}$") || Convert.ToDecimal(text) <= 0m)
                    {
                        MessageBox.Show("数量 格式不正确，此处应该为大于零的整数", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else if (this.dgProducts.SelectedRows.Count == 0)
                    {
                        MessageBox.Show("没有选择数据行，请选择数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        string[] array = new string[this.dgProducts.SelectedRows.Count];
                        for (int i = 0; i < this.dgProducts.SelectedRows.Count; i++)
                        {
                            array[i] = this.dgProducts.SelectedRows[i].Cells["产品ID"].Value.ToString();
                            if (Convert.ToInt32(this.dgProducts.SelectedRows[i].Cells["数量"].Value) % Convert.ToInt32(text) != 0)
                            {
                                MessageBox.Show(array[i] + "的数量不能被你输入的数量整除！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                        }
                        OrderItems orderItems = new OrderItems();
                        bool flag = false;
                        try
                        {
                            flag = orderItems.UpdateProductQuantity(array, Convert.ToInt32(text), '/');
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        orderItems.Dispose();
                        if (flag)
                        {
                            this.RefreshItems();
                            MessageBox.Show("更改成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
            }
        }

        private void menuUpdateProductRemark_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = InputBox.ShowBox("请输入你所要修改产品备注...", "");
                if (text != null)
                {
                    text = text.Trim();
                    if (text.Length > 64)
                    {
                        MessageBox.Show("备注 格式不正确，此处应该在 64 个字符之内", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        OrderItems orderItems = new OrderItems();
                        bool flag = false;
                        try
                        {
                            flag = orderItems.UpdateProductRemark(this._sOrderCode, text);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        orderItems.Dispose();
                        if (flag)
                        {
                            this.RefreshItems();
                            MessageBox.Show("更改成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
            }
        }

        private void menuUpdateProductRemarkForSelect_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.dgProducts.SelectedRows.Count == 0)
            {
                MessageBox.Show("没有选择数据行，请选择数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string[] array = new string[this.dgProducts.SelectedRows.Count];
                for (int i = 0; i < this.dgProducts.SelectedRows.Count; i++)
                {
                    array[i] = this.dgProducts.SelectedRows[i].Cells["产品ID"].Value.ToString();
                }
                string text = InputBox.ShowBox("请输入你所要修改产品备注...", "");
                if (text != null)
                {
                    text = text.Trim();
                    if (text.Length > 64)
                    {
                        MessageBox.Show("备注 格式不正确，此处应该在 64 个字符之内", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        OrderItems orderItems = new OrderItems();
                        bool flag = false;
                        try
                        {
                            flag = orderItems.UpdateProductRemark(array, text);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        orderItems.Dispose();
                        if (flag)
                        {
                            this.RefreshItems();
                            MessageBox.Show("更改成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
            }
        }

        private void dgProducts_KeyDown(object sender, KeyEventArgs e)
        {
        }

        private void menuUpdateProductTechnics_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Update])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.menuEditData.Checked)
            {
                MessageBox.Show("请点击 控制菜单->开始编辑订单数据 开始编辑数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单已经锁定，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能进行编辑", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.dgProducts != null && this.dgProducts.Rows.Count < 1)
            {
                MessageBox.Show("表格中没有数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                FormUpdateTechnics formUpdateTechnics = new FormUpdateTechnics(this.dgProducts.Rows[this.dgProducts.CurrentCell.RowIndex].Cells[0].Value.ToString(), this);
                formUpdateTechnics.ShowDialog();
            }
        }

        private void lklUpdateDate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (this.chkLockedData.Checked || this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经锁定或者作废，不能更改备注！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = InputBox.ShowBox("请输入你要更改的 订货日期...", this._sSpeakForDate);
                if (text != null)
                {
                    try
                    {
                        DateTime.Parse(text);
                    }
                    catch
                    {
                        MessageBox.Show("你输入的 订货日期 格式错误! 正确格式例如：2009-1-31", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    string text2 = InputBox.ShowBox("请输入你要更改的 交货日期...", this._sDeliveryDate);
                    if (text2 != null)
                    {
                        try
                        {
                            DateTime.Parse(text2);
                        }
                        catch
                        {
                            MessageBox.Show("你输入的 交货日期 格式错误! 正确格式例如：2009-1-31", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        Orders orders = new Orders();
                        bool flag = false;
                        try
                        {
                            flag = orders.UpdateDate(this._sOrderCode, text, text2);
                        }
                        catch (SqlException ex)
                        {
                            MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        orders.Dispose();
                        if (flag)
                        {
                            MessageBox.Show("操作成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            this.txtSpeakForDate.Text = text + "  交货日期:" + text2;
                            this._sSpeakForDate = text;
                            this._sDeliveryDate = text2;
                        }
                    }
                }
            }
        }

        private void menuUploadAttachment_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.Filter = "所有类型(*.*)|*.*";
            this.openFileDialog1.FileName = "";
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Stream stream;
                if ((stream = this.openFileDialog1.OpenFile()) != null)
                {
                    byte[] array = new byte[stream.Length];
                    stream.Position = 0L;
                    stream.Read(array, 0, Convert.ToInt32(stream.Length));
                    stream.Flush();
                    stream.Close();
                    string text = InputBox.ShowBox("请输入对此文件的描述...", "");
                    if (text == null)
                    {
                        text = "";
                    }
                    string text2 = this.openFileDialog1.FileName.Substring(this.openFileDialog1.FileName.LastIndexOf('\\') + 1);
                    Orders orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.AttachFile(this._nOrderID, text2, array, text.Trim());
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        MessageBox.Show("操作成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        TextBox expr_16D = this.txtAttachmentName;
                        expr_16D.Text = expr_16D.Text + text2 + ";";
                    }
                }
            }
        }

        private void lkUploadAttachment_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.menuUploadAttachment_Click(null, null);
        }

        private void lkShowAttachments_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            new FormAttachment(this, this._sOrderCode)
            {
                ShowInTaskbar = false
            }.ShowDialog();
        }

        private void menuUpdateSalesperson_Click(object sender, EventArgs e)
        {
            if (this.chkLockedData.Checked || this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经锁定或者作废，不能对其相关属性进行更改！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = FormSelectSalesperson.ShowBox("请选择业务员...");
                if (text != null)
                {
                    Orders orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.UpdatesSalesperson(this._sOrderCode, text.Trim());
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        MessageBox.Show("操作成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.txtSalesPerson.Text = text.Trim();
                    }
                }
            }
        }

        private void txtSalesPerson_DoubleClick(object sender, EventArgs e)
        {
            this.menuUpdateSalesperson_Click(null, null);
        }

        private void menuRefreshOrder_Click(object sender, EventArgs e)
        {
            this.RefreshOrder();
        }

        private void menuRefreshItems_Click(object sender, EventArgs e)
        {
            this.RefreshItems();
        }

        private void btnCreateOrder_Click(object sender, EventArgs e)
        {
            this.menuCreateOrder_Click(null, null);
        }

        private void menuCreateOrder_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_Print])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能生成订单！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                int num = -2;
                try
                {
                    num = orders.GetPrintedQuantity(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (num > -1)
                {
                    if (num > 0)
                    {
                        if (MessageBox.Show("此单已经生成了 " + num.ToString() + " 次，是否继续此次生成？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                    }
                }
                else if (num == -1)
                {
                    MessageBox.Show("没有找到此单！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                DataSet dataForOrder = this.GetDataForOrder();
                if (dataForOrder != null)
                {
                    string text = null;
                    try
                    {
                        this.saveFileDialog1.Filter = "Excel文件|*.xls";
                        this.saveFileDialog1.Title = "请选择你要输入的路径和文件名";
                        this.saveFileDialog1.InitialDirectory = AppSettings.GetAppSettings("exportOrderPath");
                        this.saveFileDialog1.FileName = this.txtOrderCode.Text + ".xls";
                        if (this.saveFileDialog1.ShowDialog() != DialogResult.OK)
                        {
                            this.saveFileDialog1.Dispose();
                            dataForOrder.Dispose();
                            return;
                        }
                        text = this.saveFileDialog1.FileName;
                        this.saveFileDialog1.Dispose();
                        File.Copy(Application.StartupPath + "\\model\\" + AppSettings.GetExcelSettings("order"), text, true);
                    }
                    catch (IOException ex3)
                    {
                        MessageBox.Show(ex3.Message + "\r\n或者是: 和你要创建的相同文件名的目标文件正在使用，不能覆盖，请把它关闭或删除后在操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        dataForOrder.Dispose();
                        return;
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        dataForOrder.Dispose();
                        return;
                    }
                    orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.PrintOnce(this._sOrderCode);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        //try
                        //{
                            ExcelOperationOrder excelOperationOrder = new ExcelOperationOrder(Application.StartupPath);
                            excelOperationOrder.MakeOrderDataToExcel(text, dataForOrder, this._sOrderCode, this._sCompanyName, this._sProjectName, DateTime.Parse(this._sSpeakForDate).ToShortDateString(), DateTime.Parse(this._sDeliveryDate).ToShortDateString(), this._sProjectLinkman, this._sProjectLinkmanPhone, this._sProjectAddress, this._sRemark, LoginInfo.OperatorName, this._sSalesPerson, this.txtYaoqiu.Text.Trim());
                        //}
                        //catch (Exception ex2)
                        //{
                        //    MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        //}
                        dataForOrder.Dispose();
                    }
                }
            }
        }

        private void menuCreateTechnicsForm_Click(object sender, EventArgs e)
        {
            //if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能生成工艺单！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            //else if (this._nOrderID == -1L)
            if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DataSet dataForOrder = this.GetDataForOrder();
                if (dataForOrder != null)
                {
                    this.saveFileDialog1.Filter = "Excel文件|*.xls";
                    this.saveFileDialog1.Title = "请选择你要输入的路径和文件名";
                    this.saveFileDialog1.InitialDirectory = AppSettings.GetAppSettings("exportOrderPath");
                    this.saveFileDialog1.FileName = this.txtOrderCode.Text + "_Technics.xls";
                    string text = null;
                    if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        text = this.saveFileDialog1.FileName;
                        this.saveFileDialog1.Dispose();
                        try
                        {
                            File.Copy(Application.StartupPath + "\\model\\" + AppSettings.GetExcelSettings("technicsForm"), text, true);
                        }
                        catch (IOException ex)
                        {
                            MessageBox.Show(ex.Message + "\r\n或者是: 和你要创建的相同文件名的目标文件正在使用，不能覆盖，请把它关闭或删除后在操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            dataForOrder.Dispose();
                            return;
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            dataForOrder.Dispose();
                            return;
                        }
                        try
                        {
                            ExcelOperationOrderForTechnics excelOperationOrderForTechnics = new ExcelOperationOrderForTechnics(Application.StartupPath);
                            excelOperationOrderForTechnics.MakeDataToExcel(text, dataForOrder, this._sOrderCode, this._sCompanyName, this._sProjectName, DateTime.Parse(this._sSpeakForDate).ToShortDateString(), DateTime.Parse(this._sDeliveryDate).ToShortDateString(), this._sProjectLinkman, this._sProjectLinkmanPhone, this._sProjectAddress, this._sRemark, this._sProcessflow, LoginInfo.OperatorName, this._sSalesPerson, this.txtYaoqiu.Text.Trim());
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        dataForOrder.Dispose();
                    }
                    else
                    {
                        this.saveFileDialog1.Dispose();
                        dataForOrder.Dispose();
                    }
                }
            }
        }

        private void btnCreateLabel_Click(object sender, EventArgs e)
        {
            this.menuCreateLabel_Click(null, null);
        }

        private void menuCreateLabel_Click(object sender, EventArgs e)
        {
            if (!this._isLocked)
            {
                MessageBox.Show("次订单需要销售 确认、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    LabelModel[] array = new LabelModel[dataForLabel.Rows.Count];
                    for (int i = 0; i < dataForLabel.Rows.Count; i++)
                    {
                        array[i] = new LabelModel(dataForLabel.Rows[i]["标签上的客户名称"].ToString(), dataForLabel.Rows[i]["公司名称"].ToString(), dataForLabel.Rows[i]["计划名称"].ToString(), dataForLabel.Rows[i]["产品ID"].ToString(), dataForLabel.Rows[i]["产品类型"].ToString(), dataForLabel.Rows[i]["类型单位"].ToString(), dataForLabel.Rows[i]["产品编号"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["宽"]), dataForLabel.Rows[i]["宽(短边)"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["高"]), dataForLabel.Rows[i]["高(短边)"].ToString(), dataForLabel.Rows[i]["加工要求"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToDecimal(dataForLabel.Rows[i]["产品价格"]), dataForLabel.Rows[i]["产品备注"].ToString(), dataForLabel.Rows[i]["产品工艺"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), "");
                    }
                    this.saveFileDialog1.Filter = "Excel文件|*.xls";
                    this.saveFileDialog1.Title = "请选择你要输入的路径和文件名";
                    this.saveFileDialog1.FileName = this.txtOrderCode.Text + "_Label.xls";
                    string text = null;
                    if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        text = this.saveFileDialog1.FileName;
                        this.saveFileDialog1.Dispose();
                        try
                        {
                            File.Copy(Application.StartupPath + "\\model\\" + AppSettings.GetExcelSettings("label"), text, true);
                        }
                        catch (IOException ex)
                        {
                            MessageBox.Show(ex.Message + "\r\n或者是: 和你要创建的相同文件名的目标文件正在使用，不能覆盖，请把它关闭或删除后在操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            dataForLabel.Dispose();
                            return;
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            dataForLabel.Dispose();
                            return;
                        }
                        try
                        {
                            ExcelOperationLabel excelOperationLabel = new ExcelOperationLabel(Application.StartupPath);
                            excelOperationLabel.MakeLabelDataToExcel(text, array);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        dataForLabel.Dispose();
                    }
                    else
                    {
                        this.saveFileDialog1.Dispose();
                        dataForLabel.Dispose();
                    }
                }
            }
        }

        private DataSet GetDataForOrder()
        {
            OrderItems orderItems = new OrderItems();
            DataSet dataSet = null;
            try
            {
                Sequence eSequence;
                if (this.menuDataSequenceByInput.Checked)
                {
                    eSequence = Sequence.ByPKID;
                }
                else
                {
                    eSequence = Sequence.BySize;
                }
                dataSet = orderItems.GetOrderItemsForOrder(this._nOrderID, eSequence);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            orderItems.Dispose();
            DataSet result;
            if (dataSet != null)
            {
                if (dataSet.Tables.Count == 2)
                {
                    if (dataSet.Tables[0].Rows.Count > 0)
                    {
                        result = dataSet;
                    }
                    else
                    {
                        MessageBox.Show("此订单中还没有数据", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        dataSet.Dispose();
                        result = null;
                    }
                }
                else
                {
                    result = null;
                }
            }
            else
            {
                result = null;
            }
            return result;
        }

        private DataTable GetDataForLabel()
        {
            DataTable dataTable = null;
            OrderItems orderItems = new OrderItems();
            try
            {
                Sequence eSequence;
                if (this.menuDataSequenceByInput.Checked)
                {
                    eSequence = Sequence.ByPKID;
                }
                else
                {
                    eSequence = Sequence.BySize;
                }
                dataTable = orderItems.GetDataForLabel(this._nOrderID, eSequence);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            orderItems.Dispose();
            DataTable result;
            if (dataTable != null)
            {
                if (dataTable.Rows.Count < 1)
                {
                    MessageBox.Show("此订单中还没有数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    dataTable.Dispose();
                    result = null;
                }
                else
                {
                    result = dataTable;
                }
            }
            else
            {
                result = null;
            }
            return result;
        }

        private void menuCreateBill_Click(object sender, EventArgs e)
        {
            //if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能生成订单的账单！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            //else
            //{
                this.saveFileDialog1.Filter = "Excel文件|*.xls";
                this.saveFileDialog1.Title = "请选择你要输入的路径和文件名";
                this.saveFileDialog1.InitialDirectory = AppSettings.GetAppSettings("exportOrderPath");
                this.saveFileDialog1.FileName = this._sOrderCode + "_Bill.xls";
                string text = null;
                if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    text = this.saveFileDialog1.FileName;
                    this.saveFileDialog1.Dispose();
                    try
                    {
                        File.Copy(Application.StartupPath + "\\model\\OrderBill.xls", text, true);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n或者是: 和你要创建的相同文件名的目标文件正在使用，不能覆盖，请把它关闭或删除后在操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    Orders orders = new Orders();
                    DataSet dataSet = null;
                    try
                    {
                        dataSet = orders.GetTypeSubtotalOfOrder(this._sOrderCode);
                    }
                    catch (SqlException ex3)
                    {
                        MessageBox.Show(ex3.Message + "\r\n\r\n数据库出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (dataSet != null)
                    {
                        if (dataSet.Tables.Count == 2)
                        {
                            try
                            {
                                ExcelOperationOrderBill excelOperationOrderBill = new ExcelOperationOrderBill(Application.StartupPath);
                                excelOperationOrderBill.MakeDataToExcel(text, dataSet, this._sOrderCode, this._sCompanyName, this._sProjectName, DateTime.Parse(this._sSpeakForDate).ToShortDateString(), this._sProjectLinkman, this._sProjectLinkmanPhone, this._sProjectAddress, this._sOperatorName);
                            }
                            catch (Exception ex2)
                            {
                                MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        else
                        {
                            MessageBox.Show("发货单可能没有数据信息！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    if (dataSet != null)
                    {
                        dataSet.Dispose();
                    }
                }
                else
                {
                    this.saveFileDialog1.Dispose();
                }
           // }
        }

        private void menuExportData_Click(object sender, EventArgs e)
        {
            this.saveFileDialog1.Filter = "xml 文件|*.xml";
            this.saveFileDialog1.Title = "请选择你要输入的路径和文件名";
            this.saveFileDialog1.InitialDirectory = AppSettings.GetAppSettings("exportOrderPath");
            this.saveFileDialog1.OverwritePrompt = true;
            this.saveFileDialog1.RestoreDirectory = true;
            this.saveFileDialog1.FileName = this._sOrderCode + ".xml";
            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string fileName = this.saveFileDialog1.FileName;
                this.saveFileDialog1.Dispose();
                try
                {
                    XmlTextWriter xmlTextWriter = new XmlTextWriter(fileName, Encoding.UTF8);
                    xmlTextWriter.WriteStartDocument(false);
                    xmlTextWriter.WriteStartElement("data");
                    xmlTextWriter.WriteAttributeString("type", "order");
                    xmlTextWriter.WriteStartElement("order");
                    xmlTextWriter.WriteAttributeString("orderCode", this._sOrderCode);
                    xmlTextWriter.WriteAttributeString("company", this._sCompanyName);
                    xmlTextWriter.WriteAttributeString("date", this._sSpeakForDate);
                    xmlTextWriter.WriteAttributeString("remark", this._sRemark);
                    for (int i = 0; i < this._dtOrderItems.Rows.Count; i++)
                    {
                        xmlTextWriter.WriteStartElement("item");
                        xmlTextWriter.WriteAttributeString("serial", this._dtOrderItems.Rows[i][0].ToString());
                        xmlTextWriter.WriteAttributeString("type", this._dtOrderItems.Rows[i][1].ToString());
                        xmlTextWriter.WriteAttributeString("ProductCode", this._dtOrderItems.Rows[i][3].ToString());
                        xmlTextWriter.WriteAttributeString("width", this._dtOrderItems.Rows[i][4].ToString());
                        xmlTextWriter.WriteAttributeString("Height", this._dtOrderItems.Rows[i][6].ToString());
                        xmlTextWriter.WriteAttributeString("quantity", this._dtOrderItems.Rows[i][8].ToString());
                        xmlTextWriter.WriteAttributeString("area", this._dtOrderItems.Rows[i][9].ToString());
                        xmlTextWriter.WriteAttributeString("price", this._dtOrderItems.Rows[i][10].ToString());
                        xmlTextWriter.WriteAttributeString("remark", this._dtOrderItems.Rows[i][11].ToString());
                        xmlTextWriter.WriteEndElement();
                    }
                    xmlTextWriter.WriteEndElement();
                    xmlTextWriter.WriteEndElement();
                    xmlTextWriter.WriteEndDocument();
                    xmlTextWriter.Flush();
                    xmlTextWriter.Close();
                }
                catch (XmlException ex)
                {
                    MessageBox.Show(ex.Message, "提示!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                this.saveFileDialog1.Dispose();
            }
        }

        private void menuExportExcelData_Click(object sender, EventArgs e)
        {
        //    if (!this._isLocked)
        //    {
        //        MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        //    }
        //    else
        //    {
                this.saveFileDialog1.Filter = "Excel文件|*.xls";
                this.saveFileDialog1.Title = "请选择你要保存的路径和文件名";
                this.saveFileDialog1.InitialDirectory = AppSettings.GetAppSettings("exportOrderPath");
                this.saveFileDialog1.FileName = "订单__" + this._sOrderCode + ".xls";
                string text = null;
                if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    text = this.saveFileDialog1.FileName;
                    this.saveFileDialog1.Dispose();
                    try
                    {
                        File.Copy(Application.StartupPath + "\\model\\" + AppSettings.GetExcelSettings("youhua"), text, true);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n或者是: 和你要创建的相同文件名的目标文件正在使用，不能覆盖，请把它关闭或删除后在操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    DataTable dataForLabel = this.GetDataForLabel();
                    if (dataForLabel != null)
                    {
                        try
                        {
                            ExcelOperationYouhuaData excelOperationYouhuaData = new ExcelOperationYouhuaData(Application.StartupPath);
                            excelOperationYouhuaData.MakeYouhuaDataToExcel(text, dataForLabel, this._sProjectName);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
                else
                {
                    this.saveFileDialog1.Dispose();
                }
            //}
        }

        private void menuExportExcelData2_Click(object sender, EventArgs e)
        {
            //if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            //else
            //{
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    this.saveFileDialog1.Filter = "Excel文件|*.xls";
                    this.saveFileDialog1.Title = "请选择你要保存的路径和文件名";
                    this.saveFileDialog1.InitialDirectory = AppSettings.GetAppSettings("exportOrderPath");
                    this.saveFileDialog1.FileName = "订单__" + this._sOrderCode + ".xls";
                    if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        string fileName = this.saveFileDialog1.FileName;
                        General general = null;
                        try
                        {
                            general = new General(Application.StartupPath + "\\model\\" + AppSettings.GetExcelSettings("youhua"), true);
                            general.MakeDataToExcel(fileName, dataForLabel);
                        }
                        catch (IOException ex)
                        {
                            MessageBox.Show(ex.Message + "\r\n或者是: 和你要创建的相同文件名的目标文件正在使用，不能覆盖，请把它关闭或删除后在操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        if (general != null)
                        {
                            general.Dispose();
                        }
                    }
                }
            //}
        }

        private void btnPrintBarCodeLabel_Click(object sender, EventArgs e)
        {
            this.menuPrintBarCodeLabel_2_Click(null, null);
        }

        private void menuPrintBarCodeLabel_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                int num = -2;
                try
                {
                    num = orders.GetPrintedQuantityForLabel(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (num > -1)
                {
                    if (num > 0)
                    {
                        if (MessageBox.Show("此单标签已经打印了 " + num.ToString() + " 次，是否继续此次打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                    }
                }
                else if (num == -1)
                {
                    MessageBox.Show("没有找到此单！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    LabelModel[] array = new LabelModel[dataForLabel.Rows.Count];
                    for (int i = 0; i < dataForLabel.Rows.Count; i++)
                    {
                        array[i] = new LabelModel(dataForLabel.Rows[i]["标签上的客户名称"].ToString(), dataForLabel.Rows[i]["公司名称"].ToString(), dataForLabel.Rows[i]["计划名称"].ToString(), dataForLabel.Rows[i]["产品ID"].ToString(), dataForLabel.Rows[i]["产品类型"].ToString(), dataForLabel.Rows[i]["类型单位"].ToString(), dataForLabel.Rows[i]["产品编号"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["宽"]), dataForLabel.Rows[i]["宽(短边)"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["高"]), dataForLabel.Rows[i]["高(短边)"].ToString(), dataForLabel.Rows[i]["加工要求"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToDecimal(dataForLabel.Rows[i]["产品价格"]), dataForLabel.Rows[i]["产品备注"].ToString(), dataForLabel.Rows[i]["产品工艺"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), "");
                    }
                    if (MessageBox.Show("是否按照数据库打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        string productType = array[0].ProductType;
                        string text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                        if (text == null)
                        {
                            return;
                        }
                        if (text.Trim().Length <= 0)
                        {
                            MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        for (int i = 0; i < array.Length; i++)
                        {
                            if (array[i].ProductType == productType)
                            {
                                array[i].ProductType = text;
                            }
                            else
                            {
                                productType = array[i].ProductType;
                                text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                                if (text == null)
                                {
                                    return;
                                }
                                if (text.Trim().Length <= 0)
                                {
                                    MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                array[i].ProductType = text;
                            }
                        }
                    }
                    orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.PrintOnceForLabel(this._sOrderCode);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        try
                        {
                            BarcodePrinter barcodePrinter = new Printer_BiaoZhun_Tsc();
                            barcodePrinter.Print(array);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }
        }

        private void menuPrintChoiceLabel_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    bool flag = true;
                    if (MessageBox.Show("按照数量打印，请点击是\r\n每个标签打印一个，请点击否", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        flag = false;
                    }
                    if (this.dgProducts.SelectedRows.Count > 0)
                    {
                        int num = 0;
                        LabelModel[] array = new LabelModel[this.dgProducts.SelectedRows.Count];
                        for (int i = 0; i < dataForLabel.Rows.Count; i++)
                        {
                            for (int j = 0; j < this.dgProducts.SelectedRows.Count; j++)
                            {
                                if (dataForLabel.Rows[i]["产品ID"].ToString() == this.dgProducts.SelectedRows[j].Cells["产品ID"].Value.ToString())
                                {
                                    array[num] = new LabelModel(dataForLabel.Rows[i]["标签上的客户名称"].ToString(), dataForLabel.Rows[i]["公司名称"].ToString(), dataForLabel.Rows[i]["计划名称"].ToString(), dataForLabel.Rows[i]["产品ID"].ToString(), dataForLabel.Rows[i]["产品类型"].ToString(), dataForLabel.Rows[i]["类型单位"].ToString(), dataForLabel.Rows[i]["产品编号"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["宽"]), dataForLabel.Rows[i]["宽(短边)"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["高"]), dataForLabel.Rows[i]["高(短边)"].ToString(), dataForLabel.Rows[i]["加工要求"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToDecimal(dataForLabel.Rows[i]["产品价格"]), dataForLabel.Rows[i]["产品备注"].ToString(), dataForLabel.Rows[i]["产品工艺"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), (!flag) ? 1 : Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), (!flag) ? 1 : Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), "");
                                    num++;
                                    break;
                                }
                            }
                        }
                        if (MessageBox.Show("是否按照数据库打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            string productType = array[0].ProductType;
                            string text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                            if (text == null)
                            {
                                return;
                            }
                            if (text.Trim().Length <= 0)
                            {
                                MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                            for (int i = 0; i < array.Length; i++)
                            {
                                if (array[i].ProductType == productType)
                                {
                                    array[i].ProductType = text;
                                }
                                else
                                {
                                    productType = array[i].ProductType;
                                    text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                                    if (text == null)
                                    {
                                        return;
                                    }
                                    if (text.Trim().Length <= 0)
                                    {
                                        MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        return;
                                    }
                                    array[i].ProductType = text;
                                }
                            }
                        }
                        try
                        {
                            BarcodePrinter barcodePrinter = new Printer_BiaoZhun_Tsc();
                            barcodePrinter.Print(array);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        MessageBox.Show("你没有选中行，请选中要打印标签的数据行在进行打印", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }

        private void menuPrintBarCodeLabel_S_Click(object sender, EventArgs e)
        {
        }

        private void menuPrintChoiceLabel_S_Click(object sender, EventArgs e)
        {
        }

        private void menuPrintBarCodeLabel_2_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                int num = -2;
                try
                {
                    num = orders.GetPrintedQuantityForLabel(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (num > -1)
                {
                    if (num > 0)
                    {
                        if (MessageBox.Show("此单标签已经打印了 " + num.ToString() + " 次，是否继续此次打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                    }
                }
                else if (num == -1)
                {
                    MessageBox.Show("没有找到此单！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    List<string> orderItems = GetOrderItems();
                    bool isAllPrint = orderItems.Count == 0;
                    LabelModel[] array = null;
                    if (isAllPrint)
                        array = new LabelModel[dataForLabel.Rows.Count];
                    else
                        array = new LabelModel[orderItems.Count];
                    int arrayIndex = 0;


                    for (int i = 0; i < dataForLabel.Rows.Count; i++)
                    {
                        if (isAllPrint || orderItems.IndexOf(dataForLabel.Rows[i]["产品ID"].ToString())>-1)
                        {
                            array[arrayIndex] = new LabelModel(dataForLabel.Rows[i]["标签上的客户名称"].ToString(), 
                                dataForLabel.Rows[i]["公司名称"].ToString(), 
                                dataForLabel.Rows[i]["计划名称"].ToString(), 
                                dataForLabel.Rows[i]["产品ID"].ToString(), 
                                dataForLabel.Rows[i]["产品类型"].ToString(), 
                                dataForLabel.Rows[i]["类型单位"].ToString(), 
                                dataForLabel.Rows[i]["产品编号"].ToString(), 
                                Convert.ToDouble(dataForLabel.Rows[i]["宽"]), 
                                dataForLabel.Rows[i]["宽(短边)"].ToString(), 
                                Convert.ToDouble(dataForLabel.Rows[i]["高"]), 
                                dataForLabel.Rows[i]["高(短边)"].ToString(), 
                                dataForLabel.Rows[i]["加工要求"].ToString(), 
                                Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), 
                                Convert.ToDecimal(dataForLabel.Rows[i]["产品价格"]), 
                                dataForLabel.Rows[i]["产品备注"].ToString(), 
                                dataForLabel.Rows[i]["产品工艺"].ToString(), 
                                Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), 
                                Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), 
                                Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), "");
                            arrayIndex++;
                        }
                    }
                    if (MessageBox.Show("是否按照数据库打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        string productType = array[0].ProductType;
                        string text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                        if (text == null)
                        {
                            return;
                        }
                        if (text.Trim().Length <= 0)
                        {
                            MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        for (int i = 0; i < array.Length; i++)
                        {
                            if (array[i].ProductType == productType)
                            {
                                array[i].ProductType = text;
                            }
                            else
                            {
                                productType = array[i].ProductType;
                                text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                                if (text == null)
                                {
                                    return;
                                }
                                if (text.Trim().Length <= 0)
                                {
                                    MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                array[i].ProductType = text;
                            }
                        }
                    }
                    orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.PrintOnceForLabel(this._sOrderCode);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        BarcodePrinter barcodePrinter = null;
                        try
                        {
                            barcodePrinter = new Printer_General_1();
                            barcodePrinter.PrintPreview(array);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        if (barcodePrinter != null)
                        {
                            barcodePrinter.Dispose();
                        }
                    }
                }
            }
        }

        private void menuPrintChoiceLabel_2_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    bool flag = true;
                    if (MessageBox.Show("按照数量打印，请点击是\r\n每个标签打印一个，请点击否", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        flag = false;
                    }
                    if (this.dgProducts.SelectedRows.Count > 0)
                    {
                        int num = 0;
                        LabelModel[] array = new LabelModel[this.dgProducts.SelectedRows.Count];
                        for (int i = 0; i < dataForLabel.Rows.Count; i++)
                        {
                            for (int j = 0; j < this.dgProducts.SelectedRows.Count; j++)
                            {
                                if (dataForLabel.Rows[i]["产品ID"].ToString() == this.dgProducts.SelectedRows[j].Cells["产品ID"].Value.ToString())
                                {
                                    array[num] = new LabelModel(dataForLabel.Rows[i]["标签上的客户名称"].ToString(), dataForLabel.Rows[i]["公司名称"].ToString(), dataForLabel.Rows[i]["计划名称"].ToString(), dataForLabel.Rows[i]["产品ID"].ToString(), dataForLabel.Rows[i]["产品类型"].ToString(), dataForLabel.Rows[i]["类型单位"].ToString(), dataForLabel.Rows[i]["产品编号"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["宽"]), dataForLabel.Rows[i]["宽(短边)"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["高"]), dataForLabel.Rows[i]["高(短边)"].ToString(), dataForLabel.Rows[i]["加工要求"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToDecimal(dataForLabel.Rows[i]["产品价格"]), dataForLabel.Rows[i]["产品备注"].ToString(), dataForLabel.Rows[i]["产品工艺"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), (!flag) ? 1 : Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), (!flag) ? 1 : Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), "");
                                    num++;
                                    break;
                                }
                            }
                        }
                        if (MessageBox.Show("是否按照数据库打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            string productType = array[0].ProductType;
                            string text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                            if (text == null)
                            {
                                return;
                            }
                            if (text.Trim().Length <= 0)
                            {
                                MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                            for (int i = 0; i < array.Length; i++)
                            {
                                if (array[i].ProductType == productType)
                                {
                                    array[i].ProductType = text;
                                }
                                else
                                {
                                    productType = array[i].ProductType;
                                    text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                                    if (text == null)
                                    {
                                        return;
                                    }
                                    if (text.Trim().Length <= 0)
                                    {
                                        MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        return;
                                    }
                                    array[i].ProductType = text;
                                }
                            }
                        }
                        BarcodePrinter barcodePrinter = null;
                        try
                        {
                            barcodePrinter = new Printer_General_1();
                            barcodePrinter.PrintPreview(array);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        if (barcodePrinter != null)
                        {
                            barcodePrinter.Dispose();
                        }
                    }
                    else
                    {
                        MessageBox.Show("你没有选中行，请选中要打印标签的数据行在进行打印", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }

        private void menuPrintBarCodeLabel_3_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                int num = -2;
                try
                {
                    num = orders.GetPrintedQuantityForLabel(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (num > -1)
                {
                    if (num > 0)
                    {
                        if (MessageBox.Show("此单标签已经打印了 " + num.ToString() + " 次，是否继续此次打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                    }
                }
                else if (num == -1)
                {
                    MessageBox.Show("没有找到此单！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    LabelModel[] array = new LabelModel[dataForLabel.Rows.Count];
                    for (int i = 0; i < dataForLabel.Rows.Count; i++)
                    {
                        array[i] = new LabelModel(dataForLabel.Rows[i]["标签上的客户名称"].ToString(), dataForLabel.Rows[i]["公司名称"].ToString(), dataForLabel.Rows[i]["计划名称"].ToString(), dataForLabel.Rows[i]["产品ID"].ToString(), dataForLabel.Rows[i]["产品类型"].ToString(), dataForLabel.Rows[i]["类型单位"].ToString(), dataForLabel.Rows[i]["产品编号"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["宽"]), dataForLabel.Rows[i]["宽(短边)"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["高"]), dataForLabel.Rows[i]["高(短边)"].ToString(), dataForLabel.Rows[i]["加工要求"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToDecimal(dataForLabel.Rows[i]["产品价格"]), dataForLabel.Rows[i]["产品备注"].ToString(), dataForLabel.Rows[i]["产品工艺"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), "");
                    }
                    if (MessageBox.Show("是否按照数据库打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        string productType = array[0].ProductType;
                        string text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                        if (text == null)
                        {
                            return;
                        }
                        if (text.Trim().Length <= 0)
                        {
                            MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        for (int i = 0; i < array.Length; i++)
                        {
                            if (array[i].ProductType == productType)
                            {
                                array[i].ProductType = text;
                            }
                            else
                            {
                                productType = array[i].ProductType;
                                text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                                if (text == null)
                                {
                                    return;
                                }
                                if (text.Trim().Length <= 0)
                                {
                                    MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                array[i].ProductType = text;
                            }
                        }
                    }
                    orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.PrintOnceForLabel(this._sOrderCode);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        BarcodePrinter barcodePrinter = null;
                        try
                        {
                            barcodePrinter = new Printer_General_TR();
                            barcodePrinter.PrintPreview(array);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        if (barcodePrinter != null)
                        {
                            barcodePrinter.Dispose();
                        }
                    }
                }
            }
        }

        private void menuPrintChoiceLabel_3_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    bool flag = true;
                    if (MessageBox.Show("按照数量打印，请点击是\r\n每个标签打印一个，请点击否", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        flag = false;
                    }
                    if (this.dgProducts.SelectedRows.Count > 0)
                    {
                        int num = 0;
                        LabelModel[] array = new LabelModel[this.dgProducts.SelectedRows.Count];
                        for (int i = 0; i < dataForLabel.Rows.Count; i++)
                        {
                            for (int j = 0; j < this.dgProducts.SelectedRows.Count; j++)
                            {
                                if (dataForLabel.Rows[i]["产品ID"].ToString() == this.dgProducts.SelectedRows[j].Cells["产品ID"].Value.ToString())
                                {
                                    array[num] = new LabelModel(dataForLabel.Rows[i]["标签上的客户名称"].ToString(), dataForLabel.Rows[i]["公司名称"].ToString(), dataForLabel.Rows[i]["计划名称"].ToString(), dataForLabel.Rows[i]["产品ID"].ToString(), dataForLabel.Rows[i]["产品类型"].ToString(), dataForLabel.Rows[i]["类型单位"].ToString(), dataForLabel.Rows[i]["产品编号"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["宽"]), dataForLabel.Rows[i]["宽(短边)"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["高"]), dataForLabel.Rows[i]["高(短边)"].ToString(), dataForLabel.Rows[i]["加工要求"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToDecimal(dataForLabel.Rows[i]["产品价格"]), dataForLabel.Rows[i]["产品备注"].ToString(), dataForLabel.Rows[i]["产品工艺"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), (!flag) ? 1 : Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), (!flag) ? 1 : Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), "");
                                    num++;
                                    break;
                                }
                            }
                        }
                        if (MessageBox.Show("是否按照数据库打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            string productType = array[0].ProductType;
                            string text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                            if (text == null)
                            {
                                return;
                            }
                            if (text.Trim().Length <= 0)
                            {
                                MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                            for (int i = 0; i < array.Length; i++)
                            {
                                if (array[i].ProductType == productType)
                                {
                                    array[i].ProductType = text;
                                }
                                else
                                {
                                    productType = array[i].ProductType;
                                    text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                                    if (text == null)
                                    {
                                        return;
                                    }
                                    if (text.Trim().Length <= 0)
                                    {
                                        MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        return;
                                    }
                                    array[i].ProductType = text;
                                }
                            }
                        }
                        BarcodePrinter barcodePrinter = null;
                        try
                        {
                            barcodePrinter = new Printer_General_TR();
                            barcodePrinter.PrintPreview(array);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        if (barcodePrinter != null)
                        {
                            barcodePrinter.Dispose();
                        }
                    }
                    else
                    {
                        MessageBox.Show("你没有选中行，请选中要打印标签的数据行在进行打印", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }

        private void menuPrintBarCodeLabel_4_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                int num = -2;
                try
                {
                    num = orders.GetPrintedQuantityForLabel(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (num > -1)
                {
                    if (num > 0)
                    {
                        if (MessageBox.Show("此单标签已经打印了 " + num.ToString() + " 次，是否继续此次打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                    }
                }
                else if (num == -1)
                {
                    MessageBox.Show("没有找到此单！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    LabelModel[] array = new LabelModel[dataForLabel.Rows.Count];
                    for (int i = 0; i < dataForLabel.Rows.Count; i++)
                    {
                        array[i] = new LabelModel(dataForLabel.Rows[i]["标签上的客户名称"].ToString(), dataForLabel.Rows[i]["公司名称"].ToString(), dataForLabel.Rows[i]["计划名称"].ToString(), dataForLabel.Rows[i]["产品ID"].ToString(), dataForLabel.Rows[i]["产品类型"].ToString(), dataForLabel.Rows[i]["类型单位"].ToString(), dataForLabel.Rows[i]["产品编号"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["宽"]), dataForLabel.Rows[i]["宽(短边)"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["高"]), dataForLabel.Rows[i]["高(短边)"].ToString(), dataForLabel.Rows[i]["加工要求"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToDecimal(dataForLabel.Rows[i]["产品价格"]), dataForLabel.Rows[i]["产品备注"].ToString(), dataForLabel.Rows[i]["产品工艺"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), "");
                    }
                    if (MessageBox.Show("是否按照数据库打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        string productType = array[0].ProductType;
                        string text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                        if (text == null)
                        {
                            return;
                        }
                        if (text.Trim().Length <= 0)
                        {
                            MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        for (int i = 0; i < array.Length; i++)
                        {
                            if (array[i].ProductType == productType)
                            {
                                array[i].ProductType = text;
                            }
                            else
                            {
                                productType = array[i].ProductType;
                                text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                                if (text == null)
                                {
                                    return;
                                }
                                if (text.Trim().Length <= 0)
                                {
                                    MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                array[i].ProductType = text;
                            }
                        }
                    }
                    orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.PrintOnceForLabel(this._sOrderCode);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        BarcodePrinter barcodePrinter = null;
                        try
                        {
                            barcodePrinter = new Printer_General_LiHua();
                            barcodePrinter.PrintPreview(array);
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        if (barcodePrinter != null)
                        {
                            barcodePrinter.Dispose();
                        }
                    }
                }
            }
        }

        private void menuPrintChoiceLabel_4_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    bool flag = true;
                    if (MessageBox.Show("按照数量打印，请点击是\r\n每个标签打印一个，请点击否", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        flag = false;
                    }
                    if (this.dgProducts.SelectedRows.Count > 0)
                    {
                        int num = 0;
                        LabelModel[] array = new LabelModel[this.dgProducts.SelectedRows.Count];
                        for (int i = 0; i < dataForLabel.Rows.Count; i++)
                        {
                            for (int j = 0; j < this.dgProducts.SelectedRows.Count; j++)
                            {
                                if (dataForLabel.Rows[i]["产品ID"].ToString() == this.dgProducts.SelectedRows[j].Cells["产品ID"].Value.ToString())
                                {
                                    array[num] = new LabelModel(dataForLabel.Rows[i]["标签上的客户名称"].ToString(), dataForLabel.Rows[i]["公司名称"].ToString(), dataForLabel.Rows[i]["计划名称"].ToString(), dataForLabel.Rows[i]["产品ID"].ToString(), dataForLabel.Rows[i]["产品类型"].ToString(), dataForLabel.Rows[i]["类型单位"].ToString(), dataForLabel.Rows[i]["产品编号"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["宽"]), dataForLabel.Rows[i]["宽(短边)"].ToString(), Convert.ToDouble(dataForLabel.Rows[i]["高"]), dataForLabel.Rows[i]["高(短边)"].ToString(), dataForLabel.Rows[i]["加工要求"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), Convert.ToDecimal(dataForLabel.Rows[i]["产品价格"]), dataForLabel.Rows[i]["产品备注"].ToString(), dataForLabel.Rows[i]["产品工艺"].ToString(), Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), (!flag) ? 1 : Convert.ToInt32(dataForLabel.Rows[i]["产品数量"]), (!flag) ? 1 : Convert.ToInt32(dataForLabel.Rows[i]["标签倍数"]), "");
                                    num++;
                                    break;
                                }
                            }
                        }
                        if (MessageBox.Show("是否按照数据库打印？", "提示！", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            string productType = array[0].ProductType;
                            string text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                            if (text == null)
                            {
                                return;
                            }
                            if (text.Trim().Length <= 0)
                            {
                                MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                            for (int i = 0; i < array.Length; i++)
                            {
                                if (array[i].ProductType == productType)
                                {
                                    array[i].ProductType = text;
                                }
                                else
                                {
                                    productType = array[i].ProductType;
                                    text = InputBox.ShowBox("请输入你要打印标签所要更改的类型...", productType);
                                    if (text == null)
                                    {
                                        return;
                                    }
                                    if (text.Trim().Length <= 0)
                                    {
                                        MessageBox.Show("你没有输入数据！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        return;
                                    }
                                    array[i].ProductType = text;
                                }
                            }
                        }
                        BarcodePrinter barcodePrinter = null;
                        try
                        {
                            barcodePrinter = new Printer_General_LiHua();
                            barcodePrinter.PrintPreview(array);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        if (barcodePrinter != null)
                        {
                            barcodePrinter.Dispose();
                        }
                    }
                    else
                    {
                        MessageBox.Show("你没有选中行，请选中要打印标签的数据行在进行打印", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }

        private void menuExportProcessflowLabelData_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    string sSavePath = AppSettings.GetAppSettings("exportOrderPath") + "\\__加工标签.xls";
                    ExportProcessflowLabelData exportProcessflowLabelData = null;
                    try
                    {
                        exportProcessflowLabelData = new ExportProcessflowLabelData(Application.StartupPath + "\\model\\" + AppSettings.GetExcelSettings("ExportProcessflowLabelData"), true);
                        exportProcessflowLabelData.MakeDataToExcel(sSavePath, dataForLabel);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n或者是: 和你要创建的相同文件名的目标文件正在使用，不能覆盖，请把它关闭或删除后在操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    if (exportProcessflowLabelData != null)
                    {
                        exportProcessflowLabelData.Dispose();
                    }
                }
            }
        }

        private void menuExportProductLabelData_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_PrintLabel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //else if (!this._isLocked)
            //{
            //    MessageBox.Show("此订单需要销售 审核、锁定 后方能打印标签！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            else if (this._nOrderID == -1L)
            {
                MessageBox.Show("加载数据时出现了错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DataTable dataForLabel = this.GetDataForLabel();
                if (dataForLabel != null)
                {
                    string sSavePath = AppSettings.GetAppSettings("exportOrderPath") + "\\__成品标签.xls";
                    ExportProductLabelData exportProductLabelData = null;
                    try
                    {
                        exportProductLabelData = new ExportProductLabelData(Application.StartupPath + "\\model\\" + AppSettings.GetExcelSettings("ExportProductLabelData"), true);
                        exportProductLabelData.MakeDataToExcel(sSavePath, dataForLabel);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n或者是: 和你要创建的相同文件名的目标文件正在使用，不能覆盖，请把它关闭或删除后在操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    if (exportProductLabelData != null)
                    {
                        exportProductLabelData.Dispose();
                    }
                }
            }
        }

        private void menuCreateOrderBySameProject_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_Create])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                FormAddOrder formAddOrder = new FormAddOrder(this._nCustomerID, this.txtCompanyName.Text, this._nProjectID, this.txtProjectAddress.Text);
                formAddOrder.MdiParent = base.MdiParent;
                formAddOrder.Show();
                formAddOrder.Activate();
            }
        }

        private void menuLailiao_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_UnLock])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.Lailiao(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    MessageBox.Show("设置成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.ckLailiao.Checked = true;
                }
            }
        }

        private void menuUnLailiao_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_UnLock])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.UnLailiao(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    MessageBox.Show("设置成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.ckLailiao.Checked = false;
                }
            }
        }

        private void menuQuliao_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_UnLock])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.Quliao(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    MessageBox.Show("设置成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.ckQuliao.Checked = true;
                }
            }
        }

        private void menuUnQuliao_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_UnLock])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.UnQuliao(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    MessageBox.Show("设置成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.ckQuliao.Checked = false;
                }
            }
        }

        private void chkPayment_Click(object sender, EventArgs e)
        {
            if (this.chkPayment.Checked)
            {
                this.menuNotPayed_Click(null, null);
            }
            else
            {
                this.menuPayed_Click(null, null);
            }
        }

        private void menuPayed_Click(object sender, EventArgs e)
        {
        }

        private void menuNotPayed_Click(object sender, EventArgs e)
        {
        }

        private void menuAddPayment_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_Payed])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                FormOrderPayment formOrderPayment = new FormOrderPayment(this._sOrderCode);
                formOrderPayment.ShowDialog();
            }
        }

        private void menuPaymentInfo_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_Payed])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                FormPaymentList formPaymentList = new FormPaymentList(new OrderCondition
                {
                    OrderCode = this._sOrderCode
                });
                if (formPaymentList != null && !formPaymentList.IsDisposed)
                {
                    formPaymentList.MdiParent = base.MdiParent;
                    formPaymentList.Show();
                    formPaymentList.Activate();
                }
            }
        }

        private void chkLockedData_Click(object sender, EventArgs e)
        {
            if (this.chkLockedData.Checked)
            {
                this.menuUnLockData_Click(null, null);
            }
            else
            {
                this.menuLockData_Click(null, null);
            }
        }

        private void menuLockData_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_Lock])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.chkEdited.Checked)
            {
                MessageBox.Show("此订单还没有经过操作者确认编辑完成！请等候操作完成在锁定。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.LockData(this._nOrderID);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    this._isLocked = true;
                    this.chkLockedData.Checked = true;
                }
            }
        }

        private void menuUnLockData_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_UnLock])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkPayment.Checked)
            {
                MessageBox.Show("此单已经结算，不能再进行修改！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.UnLockData(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    this._isLocked = false;
                    this.chkLockedData.Checked = false;
                }
            }
        }

        private void chkCancelled_Click(object sender, EventArgs e)
        {
            if (this.chkCancelled.Checked)
            {
                this.menuActivate_Click(null, null);
            }
            else
            {
                this.menuCancel_Click(null, null);
            }
        }

        private void menuCancel_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_Cancel])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkPayment.Checked)
            {
                MessageBox.Show("此单已经结算，不能再进行修改！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.Cancel(this._nOrderID);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    this._isCancelled = true;
                    this.chkCancelled.Checked = true;
                }
            }
        }

        private void menuActivate_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.Order_Activate])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.Activate(this._nOrderID);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    this._isCancelled = false;
                    this.chkCancelled.Checked = false;
                }
            }
        }

        private void menuEditData_Click(object sender, EventArgs e)
        {
            if (!this.menuEditData.Checked)
            {
                if (this.chkEdited.Checked)
                {
                    MessageBox.Show("此订单已经设置编辑完成！请解除后再操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (this.chkLockedData.Checked)
                {
                    MessageBox.Show("此订单数据已经锁定！请解锁后再操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (this.chkCancelled.Checked)
                {
                    MessageBox.Show("此订单数据已经作废！请激活后再操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    Orders orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.StartUseOrder(this._nOrderID, LoginInfo.OperatorID, this._hostIPAddress);
                    }
                    catch (SqlException ex)
                    {
                        if (ex.Number == 2627)
                        {
                            MessageBox.Show("此订单有人正在使用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            this.Text = "订单详细信息—-＞此订单有人正在使用！";
                        }
                        else
                        {
                            MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        this.menuEditData.Checked = true;
                        this.Text = "订单详细信息—-＞正在编辑...";
                        this.btnAddOrderItem_Click(null, null);
                    }
                }
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.StopUseOrder(this._nOrderID);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    this.menuEditData.Checked = false;
                    this.Text = "订单详细信息—-＞已经停止编辑";
                }
            }
        }

        private void chkEdited_Click(object sender, EventArgs e)
        {
            this.menuEdited_Click(null, null);
        }

        private void menuEdited_Click(object sender, EventArgs e)
        {
            if (this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单数据已经锁定！请解锁后再操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单数据已经作废！请激活后再操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.chkEdited.Checked)
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.Edited(this._nOrderID, !this.chkEdited.Checked);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    this._isEdited = true;
                    this.chkEdited.Checked = true;
                }
            }
            else if (!LoginInfo.Role[PowerName.Order_UnEdited])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.Edited(this._nOrderID, !this.chkEdited.Checked);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    this._isEdited = false;
                    this.chkEdited.Checked = false;
                }
            }
        }

        private void menuDataSequenceByInput_Click(object sender, EventArgs e)
        {
            this.menuDataSequenceByInput.Checked = true;
            this.menuDataSequenceBySize.Checked = false;
            this.RefreshItems();
        }

        private void menuDataSequenceBySize_Click(object sender, EventArgs e)
        {
            this.menuDataSequenceByInput.Checked = false;
            this.menuDataSequenceBySize.Checked = true;
            this.RefreshItems();
        }

        private void menuShowSubtenseColumn_Click(object sender, EventArgs e)
        {
            if (this._dtOrderItems != null)
            {
                if (this.dgProducts.Columns["宽(短边)"].Visible)
                {
                    this.dgProducts.Columns["宽(短边)"].Visible = false;
                    this.dgProducts.Columns["高(短边)"].Visible = false;
                }
                else
                {
                    this.dgProducts.Columns["宽(短边)"].Visible = true;
                    this.dgProducts.Columns["高(短边)"].Visible = true;
                }
            }
        }

        private void menuShowData_Click(object sender, EventArgs e)
        {
            if (this.menuShowData.Checked)
            {
                this.menuShowData.Checked = false;
                this.menuShowData.Text = "暂时不显示所输入的数据";
            }
            else
            {
                this.menuShowData.Checked = true;
                this.menuShowData.Text = "显示所输入的数据";
            }
        }

        private void menuTypeSortArea_Click(object sender, EventArgs e)
        {
            Orders orders = new Orders();
            DataSet dataSet = null;
            try
            {
                dataSet = orders.GetTypeSubtotalOfOrder(this._sOrderCode);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            orders.Dispose();
            if (dataSet != null)
            {
                if (dataSet.Tables.Count == 2)
                {
                    string text = "※ 订单的分类信息如下：\r\n";
                    int num = 0;
                    decimal d = 0m;
                    decimal d2 = 0m;
                    decimal d3 = 0m;
                    string text2;
                    for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                    {
                        int num2 = Convert.ToInt32(dataSet.Tables[0].Rows[i][1]);
                        num += num2;
                        decimal num3 = Convert.ToDecimal(dataSet.Tables[0].Rows[i][2]);
                        d += num3;
                        decimal d4 = Convert.ToDecimal(dataSet.Tables[0].Rows[i][3]);
                        d2 += d4;
                        decimal d5 = Convert.ToDecimal(dataSet.Tables[0].Rows[i][4]);
                        decimal d6 = Convert.ToDecimal((num3 * d5).ToString("F4"));
                        d3 += d6;
                        text2 = text;
                        text = string.Concat(new string[]
                        {
                            text2,
                            "\r\n",
                            (i + 1).ToString().PadRight(3, ' '),
                            "、类型：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][0].ToString(), 16),
                            "数量：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][1].ToString(), 10),
                            "面积：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][2].ToString(), 16),
                            "周长：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[0].Rows[i][3].ToString(), 16),
                            LoginInfo.Role[PowerName.OrderData_SeePrice] ? ("价格：" + dataSet.Tables[0].Rows[i][4].ToString()) : ""
                        });
                    }
                    text2 = text;
                    text = string.Concat(new string[]
                    {
                        text2,
                        "\r\n\r\n     ★数量为：",
                        num.ToString(),
                        "；   总平方为：",
                        d.ToString(),
                        "；   总周长为：",
                        d2.ToString(),
                        LoginInfo.Role[PowerName.OrderData_SeePrice] ? ("；   金额为：" + d3.ToString()) : ""
                    });
                    text += "\r\n\r\n※ 工艺分类信息如下：\r\n";
                    decimal d7 = 0m;
                    decimal num4 = 0m;
                    for (int i = 0; i < dataSet.Tables[1].Rows.Count; i++)
                    {
                        d7 += Convert.ToDecimal(dataSet.Tables[1].Rows[i][1]);
                        num4 = Convert.ToDecimal((num4 + Convert.ToDecimal(dataSet.Tables[1].Rows[i][1]) * Convert.ToDecimal(dataSet.Tables[1].Rows[i][2])).ToString("F4"));
                        text2 = text;
                        text = string.Concat(new string[]
                        {
                            text2,
                            "\r\n",
                            (i + 1).ToString().PadRight(3, ' '),
                            "、工艺：",
                            CommonMethod.PadSpaceOnRight(dataSet.Tables[1].Rows[i][0].ToString(), 16),
                            "数量：",
                            CommonMethod.PadSpaceOnRight(Convert.ToDecimal(dataSet.Tables[1].Rows[i][1]).ToString(), 16),
                            LoginInfo.Role[PowerName.OrderData_SeePrice] ? ("价格：" + dataSet.Tables[1].Rows[i][2].ToString()) : ""
                        });
                    }
                    text = text + "\r\n\r\n     ★加工工艺的数量为：" + d7.ToString() + (LoginInfo.Role[PowerName.OrderData_SeePrice] ? ("；   加工工艺的金额为：" + num4.ToString()) : "");
                    if (LoginInfo.Role[PowerName.OrderData_SeePrice])
                    {
                        text = text + "\r\n\r\n◆ 总金额为：" + (d3 + num4).ToString("F2");
                    }
                    MessageBox.Show(text, "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show("订单中可能没有数据信息！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            if (dataSet != null)
            {
                dataSet.Dispose();
            }
        }

        private void menuNumberOfRows_Click(object sender, EventArgs e)
        {
            Orders orders = new Orders();
            double num = 0.0;
            try
            {
                num = (double)orders.GetNumberOfRows(this._sOrderCode);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            orders.Dispose();
            MessageBox.Show(num.ToString(), "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }

        private void menuAutoCreateFlowcard_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Create])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!this.chkLockedData.Checked)
            {
                MessageBox.Show("此订单必须锁定，才能创建流程卡！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经作废，不能创建流程卡！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.menuLockFlowcard.Checked)
            {
                MessageBox.Show("已经锁定流程卡，不能操作流程卡！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Flowcards flowcards = new Flowcards();
                bool flag = false;
                try
                {
                    flag = flowcards.AutoInsertOrder(this._nOrderID, this._nOperatorID);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                flowcards.Dispose();
                if (flag)
                {
                    MessageBox.Show("创建成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }

        private void menuManualCreateFlowcard_Click(object sender, EventArgs e)
        {
        }

        private void menuDeleteFlowcard_Click(object sender, EventArgs e)
        {
            if (!LoginInfo.Role[PowerName.OrderData_Delete])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (this.menuLockFlowcard.Checked)
            {
                MessageBox.Show("已经锁定流程卡，不能操作流程卡！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Flowcards flowcards = new Flowcards();
                bool flag = false;
                try
                {
                    flag = flowcards.Delete(this._nOrderID);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                flowcards.Dispose();
                if (flag)
                {
                    MessageBox.Show("操作成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }

        private void menuOpenFlowcard_Click(object sender, EventArgs e)
        {
            FormFlowcardList formFlowcardList = new FormFlowcardList(new OrderCondition
            {
                OrderCode = this._sOrderCode
            });
            if (formFlowcardList != null && !formFlowcardList.IsDisposed)
            {
                formFlowcardList.MdiParent = base.MdiParent;
                formFlowcardList.Show();
                formFlowcardList.Activate();
            }
        }

        private void menuLockFlowcard_Click(object sender, EventArgs e)
        {
            if (!this.menuLockFlowcard.Checked)
            {
                if (!LoginInfo.Role[PowerName.Order_Lock])
                {
                    MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (!this.chkLockedData.Checked)
                {
                    MessageBox.Show("此订单数据没有锁定！请锁定后再操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (this.chkCancelled.Checked)
                {
                    MessageBox.Show("此订单数据已经作废！请激活后再操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    Flowcards flowcards = new Flowcards();
                    bool flag = false;
                    try
                    {
                        flag = flowcards.LockFlowcard(this._sOrderCode);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    flowcards.Dispose();
                    if (flag)
                    {
                        this.menuLockFlowcard.Checked = true;
                    }
                }
            }
            else if (!LoginInfo.Role[PowerName.Order_UnLock])
            {
                MessageBox.Show("你没有操作这里的权限！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Flowcards flowcards = new Flowcards();
                bool flag = false;
                try
                {
                    flag = flowcards.UnLockFlowcard(this._sOrderCode);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                flowcards.Dispose();
                if (flag)
                {
                    this.menuLockFlowcard.Checked = false;
                }
            }
        }

        private void lkUpdateRemark_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (this.chkLockedData.Checked || this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经锁定或者作废，不能更改备注！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = InputBox.ShowBox("请输入你要更改的备注...", this.txtRemark.Text);
                if (text != null)
                {
                    Orders orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.UpdateRemark(this._sOrderCode, text.Trim());
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        MessageBox.Show("更改备注成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.txtRemark.Text = text.Trim();
                        this._sRemark = this.txtRemark.Text;
                    }
                }
            }
        }

        private void lkUpdateLabelName_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (this.chkLockedData.Checked || this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经锁定或者作废，不能对其相关属性进行更改！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = InputBox.ShowBox("请输入你要更改的标签名称...", this.txtLabelName.Text);
                if (text != null)
                {
                    Orders orders = new Orders();
                    bool flag = false;
                    try
                    {
                        flag = orders.UpdateCustomerNameOnPrintedLabel(this._sOrderCode, text.Trim());
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception ex2)
                    {
                        MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    orders.Dispose();
                    if (flag)
                    {
                        MessageBox.Show("更改成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.txtLabelName.Text = text.Trim();
                        this._sCustomerNameOnPrintedLabel = text.Trim();
                    }
                }
            }
        }

        private void btnInvoiceList_Click(object sender, EventArgs e)
        {
            try
            {
                string text = this.dgProducts.Rows[0].Cells[0].Value.ToString();
            }
            catch
            {
                MessageBox.Show("表格中没有数据", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            int rowIndex = this.dgProducts.CurrentCell.RowIndex;
            FormInvoiceList formInvoiceList = new FormInvoiceList(this.dgProducts.Rows[rowIndex].Cells[0].Value.ToString());
            formInvoiceList.MdiParent = base.MdiParent;
            formInvoiceList.Show();
            formInvoiceList.Activate();
        }

        private void btnYaoqiu_Click(object sender, EventArgs e)
        {
            if (this.chkLockedData.Checked || this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经锁定或者作废，不能更改备注！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.UpdateYaoqiu(this._sOrderCode, this.txtYaoqiu.Text.Trim());
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    MessageBox.Show("操作成功！", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void dgProducts_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            this._sOriginalValue = this.dgProducts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Trim();
        }

        private void dgProducts_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
        }

        private void dgProducts_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
        }

        private void dgProducts_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
        }

        private void btnProcessFlow_Click(object sender, EventArgs e)
        {
            this.panel1.Show();
            string[] array = null;
            if (this.txtProcessFlow.Text.Trim() != "")
            {
                array = this.txtProcessFlow.Text.Split(new string[]
                {
                    "—＞"
                }, StringSplitOptions.RemoveEmptyEntries);
            }
            if (array != null)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] == "切割")
                    {
                        this.ck切割.Checked = true;
                    }
                    if (array[i] == "磨边")
                    {
                        this.ck磨边.Checked = true;
                    }
                    if (array[i] == "洗片")
                    {
                        this.ck洗片.Checked = true;
                    }
                    if (array[i] == "孔缺")
                    {
                        this.ck孔缺.Checked = true;
                    }
                    if (array[i] == "钢化")
                    {
                        this.ck钢化.Checked = true;
                    }
                    if (array[i] == "磨砂")
                    {
                        this.ck磨砂.Checked = true;
                    }
                    if (array[i] == "中空")
                    {
                        this.ck中空.Checked = true;
                    }
                    if (array[i] == "夹胶")
                    {
                        this.ck夹胶.Checked = true;
                    }
                    if (array[i] == "发货")
                    {
                        this.ck发货.Checked = true;
                    }
                    if (array[i] == "包装")
                    {
                        this.ck包装.Checked = true;
                    }
                    if (array[i] == "搬运")
                    {
                        this.ck搬运.Checked = true;
                    }
                }
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.chkLockedData.Checked || this.chkCancelled.Checked)
            {
                MessageBox.Show("此订单已经锁定或者作废，不能更改 工艺流程！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = "";
                if (this.ck切割.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck切割.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck切割.Text;
                    }
                }
                if (this.ck磨边.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck磨边.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck磨边.Text;
                    }
                }
                if (this.ck洗片.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck洗片.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck洗片.Text;
                    }
                }
                if (this.ck孔缺.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck孔缺.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck孔缺.Text;
                    }
                }
                if (this.ck钢化.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck钢化.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck钢化.Text;
                    }
                }
                if (this.ck磨砂.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck磨砂.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck磨砂.Text;
                    }
                }
                if (this.ck中空.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck中空.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck中空.Text;
                    }
                }
                if (this.ck夹胶.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck夹胶.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck夹胶.Text;
                    }
                }
                if (this.ck发货.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck发货.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck发货.Text;
                    }
                }
                if (this.ck包装.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck包装.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck包装.Text;
                    }
                }
                if (this.ck搬运.Checked)
                {
                    if (text == "")
                    {
                        text = this.ck搬运.Text;
                    }
                    else
                    {
                        text = text + "—＞" + this.ck搬运.Text;
                    }
                }
                this.txtProcessFlow.Text = text;
                this._sProcessflow = text;
                Orders orders = new Orders();
                bool flag = false;
                try
                {
                    flag = orders.UpdateProcessflow(this._sOrderCode, this.txtProcessFlow.Text.Trim());
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                orders.Dispose();
                if (flag)
                {
                    this.panel1.Hide();
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.panel1.Hide();
        }

        private List<string> GetOrderItems()
        {
            List<string> orderItems = new List<string>();

            for (int i = 0; i < dgProducts.Rows.Count; i++)
            {
                if (dgProducts.Rows[i].Selected == true)
                {
                    orderItems.Add(dgProducts.Rows[i].Cells["产品ID"].Value.ToString());
                }
            }

            return orderItems;
        }

    }
}
